Imports Microsoft.VisualBasic
Imports System.Data
Imports DotNetNuke.UI.WebControls

'This class serves as a sample data service layer, where in a normal app the entity object values
'would be assigned as a result of a database call.  Since this is just a demo, hardcoded values will do just fine.
Public Class DataServices
	Public Shared Function GetTabData(ByVal id As Integer) As PageInfo	 'DataTable
		Dim oInfo As PageInfo = New PageInfo
		oInfo.id = id
		oInfo.pagename = "Some PageName"
		oInfo.name = "Some Name"
		oInfo.description = "Some Description"
		oInfo.font = "Arial"
		oInfo.color = "green"

		Return oInfo
    End Function

    Public Shared Sub PopulateList(ByVal Nodes As DNNNodeCollection, ByVal Text As String, ByVal MaxRows As Integer, ByVal CaseSensitive As Boolean)
        Dim o As DNNNode

        Dim dt As DataTable = GetData()
        Text = Text.Replace("[", "").Replace("]", "").Replace("'", "''")        'keeping things simple so strip out troublesome chars for Select below
        dt.CaseSensitive = CaseSensitive
        Dim drs() As DataRow = dt.Select("name like '" & Text & "%'")
        Dim dr As DataRow

        For Each dr In drs
            If MaxRows = 0 OrElse Nodes.Count < (MaxRows + 1) Then          '+1 to let control know there is more "pending"
                o = New DNNNode(CStr(dr("name")))
                o.ID = CStr(dr("id"))
                If dr("flag") = 1 Then
                    'o.ClickAction = eClickAction.Navigate
                    'o.NavigateURL = "http://www.dotnetnuke.com/Development/CoreTeam/tabid/698/Default.aspx"
                Else
                    o.CSSClass = "SpecialNode"
                    'o.ClickAction = eClickAction.PostBack
                End If
                Nodes.Add(o)
            End If
        Next
    End Sub

    Public Shared Function GetData() As DataTable

        Dim dt As DataTable = New DataTable
        Dim dr As DataRow
        Dim o As DataColumn

        dt.Columns.Add(New DataColumn("id", GetType(String)))
        dt.Columns.Add(New DataColumn("name", GetType(String)))
        dt.Columns.Add(New DataColumn("flag", GetType(Integer)))

        AddRow(1, "Adams", 0, dt)
        AddRow(2, "Addison", 0, dt)
        AddRow(3, "Smith", 0, dt)
        AddRow(4, "Williams", 0, dt)
        For i As Integer = 1 To 50
            AddRow(100 + i, "Smith" & i, 0, dt)
        Next

        AddRow(6, "Jordon", 0, dt)
        AddRow(7, "Jackson", 0, dt)
        AddRow(8, "Bell", 0, dt)
        AddRow(9, "Carter", 0, dt)
        AddRow(10, "Crawford", 0, dt)
        AddRow(11, "Walker", 1, dt)
        AddRow(12, "Santry", 1, dt)
        AddRow(13, "Brinkman", 1, dt)
        AddRow(14, "Caron", 1, dt)
        AddRow(15, "McCulloch", 1, dt)
        AddRow(16, "Willhite", 1, dt)
        AddRow(17, "Hopkins", 1, dt)
        AddRow(18, "Nurse", 1, dt)
        AddRow(19, "Paterra", 1, dt)
        AddRow(20, "Beadle", 1, dt)
        AddRow(21, "Colley", 1, dt)
        AddRow(22, "Masabas", 1, dt)
        AddRow(23, "Veenstra", 1, dt)
        AddRow(24, "White", 1, dt)
        AddRow(25, "Corderman", 1, dt)
        AddRow(26, "Norgaard", 1, dt)
        AddRow(27, "Andrews", 1, dt)
        AddRow(28, "Connolly", 1, dt)
        AddRow(29, "Hammond", 1, dt)
        AddRow(30, "Messerli", 1, dt)
        AddRow(31, "Haggard", 1, dt)
        AddRow(32, "Mitchell", 1, dt)
        AddRow(33, "Henning", 1, dt)
        AddRow(34, "Duffy", 1, dt)
        AddRow(35, "Pointer", 1, dt)
        AddRow(36, "Young", 1, dt)
        AddRow(37, "Hoskins", 1, dt)
        AddRow(38, "Fraser", 1, dt)
        AddRow(39, "Meiers", 1, dt)
        AddRow(40, "Garyga", 1, dt)
        Return dt
    End Function

    Private Shared Sub AddRow(ByVal ID As Integer, ByVal Name As String, ByVal Flag As Integer, ByVal dt As DataTable)
        Dim dr As DataRow = dt.NewRow()
        dr("id") = ID
        dr("name") = Name
        dr("flag") = Flag
        dt.Rows.Add(dr)
    End Sub

End Class

